package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.ScadaRtuBaseInfo;

public interface ExdeScadaRtuBaseRepository extends JpaRepository<ScadaRtuBaseInfo, String>{

	@Query(" select s from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') ")
	Page<ScadaRtuBaseInfo> getScadaRtuBaseInfos(String key, Pageable pageable);

	@Query(" select s from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') "
			+ "and s.user.saleArea.superior = ?2 ")
	Page<ScadaRtuBaseInfo> getScadaRtuBaseInfos(String key, String superior, Pageable pageable);

	@Query(" select s from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') "
			+ "and s.user.saleArea.superior = ?2 and s.user.saleArea.areaName = ?3 ")
	Page<ScadaRtuBaseInfo> getScadaRtuBaseInfos(String key, String superior, String areaName, Pageable pageable);

	@Query(" select s from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') "
			+ "and s.user = ?2 ")
	Page<ScadaRtuBaseInfo> getScadaRtuBaseInfosByUser(String key, String userId, Pageable pageable);

	@Query(" select count(*) from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') ")
	long getScadaRtuBaseInfosCount(String key);

	@Query(" select count(*) from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') "
			+ "and s.user.saleArea.superior = ?2 ")
	long getScadaRtuBaseInfosCount(String key, String superior);

	@Query(" select count(*) from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') "
			+ "and s.user.saleArea.superior = ?2 and s.user.saleArea.areaName = ?3 ")
	long getScadaRtuBaseInfosCount(String key, String superior, String areaName);

	@Query(" select count(*) from ScadaRtuBaseInfo s where (s.name like '%'+?1+'%' or s.alias like '%'+?1+'%' or s.memo like '%'+?1+'%') "
			+ "and s.user = ?2 ")
	long getScadaRtuBaseInfosByUserCount(String key, String userId);

	@Query(" select s from ScadaRtuBaseInfo s where s.id in (?1)")
	List<ScadaRtuBaseInfo> findids(String ids);

}
